<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/public/header.jsp"%>

<html>
	<head>
		<title>材料档案</title>
	</head>
	<script type="text/javascript">
		$(function(){
			$("#searchValue").keypress(function(e) { 
		    	// 回车键事件 
		     	if(e.which == 13) { 
		     		 doSearch();
		       	} 
		   	}); 
			$("#material_type_id").combotree({
				url:'<%=contextPath %>/springMVC/group/getSystemTypeTree?type=0',
				method:'POST',
				animate:true,
				lines:true,
				onChange:function(){
					doSearch();
				}
			});
			
			$("#table").datagrid({
				title:"材料档案",
				iconCls:'icon-edit',
				loadMsg:'正在加载数据，请稍后......',
				url:'<%=contextPath %>/springMVC/warehouse/listPageMaterial',
				rownumbers:true,
				fitColumns:true,
				nowrap:false,
				idField:'id',
				frozenColumns:[[
	                {field:'ck',checkbox:true},
				    {title:'编号',field:'id',hidden:true}
				]],
				columns:[[
					{title:'材料编码',field:'code',width:50,align:'center'},
					{title:'材料名称',field:'name',width:100,align:'center'},
					{title:'规格、型号',field:'format_type',width:100,align:'center'},
					{title:'计量单位',field:'unit_name',width:50,align:'center'},
					{title:'分类',field:'material_type_name',width:100,align:'center'},
					{title:'编辑',field:'edit',fit:true,width:50,align:'center',formatter:function(value,rowDate,rowIndex){
						return "<input type='button'  style='border:0px #ff0000 solid;width:25px;height:15px;cursor:pointer'class='icon-modify'  onClick='addOrEditMaterial(1,\""+rowDate.id+"\")'/>";
					}}
				]],
				toolbar:"#tb",
				pageSize:10,
				pageList : [10,50,100],  
				pagination:true,
				onLoadSuccess:function(rtJson){
					if(rtJson.rtState== '1')
					{
						$.messager.alert('提示',rtJson.rtMsrg);
					}
				},
				onDblClickRow:function(rowIndex,rowData){
					addOrEditMaterial(1,rowData.id);
				}
			});
		});
		
		function deleteRows(){
			var rows=$('#table').datagrid('getSelections');
			var deleteVar="";
			if(rows.length==0)
			{
				$.messager.alert('提示','选中要删除的记录');  
				return ;
			}
			for(var i=0;i<rows.length;i++)
			{
				if(i==(rows.length-1))
				{
					deleteVar+=rows[i].id;
				}else
				{
					deleteVar+=rows[i].id+",";
				}
			}
			$.messager.confirm('确认','您确认删除该记录信息？',function(msg){
				if(msg){
					$.ajax({
						type:'POST',
						url:"<%=contextPath %>/springMVC/warehouse/deleteMaterial",
						data:"ids="+deleteVar,
						dataType:"json",
						success:function(rtJson){
							if(rtJson.rtState == '0'){
								table_reload(rows.length);
							}
							else{
								warningInfo(rtJson.rtMsrg);
							}
						}
					});
				}
			});
		}
		function rtCallBack(){
			$('#table').datagrid('reload');
		}
		function addOrEditMaterial(type,id){
			if(type==0){
				openDialogResize("<%=contextPath %>/springViews/warehouse/addOrEditMaterial.jsp?callback=rtCallBack",1000, 800);
			}else{
				openDialogResize('<%=contextPath %>/springViews/warehouse/addOrEditMaterial.jsp?callback=rtCallBack&id='+id,1000, 800);
			}
		}
		function doSearch()
		{
			var searchValue = $('#searchValue').val();
			var material_type_id = $('#material_type_id').combotree('getValue');
			$('#table').datagrid('load',{
				searchValue:searchValue,
				material_type_id:material_type_id
				});
		}
	</script>
	<body>
		<div id="table"></div>
		<div id="tb" style="padding:3px;height:auto">
			<div style="float:left;">
				<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="deleteRows();">删除</a>
				<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="addOrEditMaterial(0);">新增</a>
			</div>
			<div align="right">
				分类：<input  id="material_type_id" name="material_type_id" class="easyui-combotree">
				查询条件：<input id="searchValue" name="searchValue" style="width:150px" title="材料编码或名称"/>&nbsp;&nbsp;
				<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch();"></a>
			</div>
		</div>
	</body>
</html>
